package com.example.administrator.testdagger.countdown;

import android.content.Context;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ProgressBar;

import com.example.administrator.testdagger.R;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Description: 
 * ModelName:
 *
 * @author WangJQ
 *Create at:  2018/6/1 18:10
 * Company: 沈阳艾尔时代科技发展有限公司
 * Copyright: (c)2018 AIR Times Inc. All rights reserved.
 * @version 1.0
 */

public class ProgressAdapter extends BaseAdapter {
    HashMap<Integer, View> mHashMap = new HashMap<>();

    ArrayList<Bean> mList = new ArrayList<>();

    Context mContext;
    private LayoutInflater mInflater;

    private void init(){


    }

    public ProgressAdapter(Context context) {
        mContext = context;
        this.mInflater = LayoutInflater.from(context);
        countDownTimer.start();
    }

    @Override
    public int getCount() {
        return 20;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        convertView = mInflater.inflate(R.layout.item_pb, null);
        Log.d("WJQ","tticksadfsss: "+convertView.getId());
        holder = new ViewHolder();
        holder.cdp = convertView.findViewById(R.id.pb);
        holder.cdp.setMax(100);
        holder.cdp.setProgress(10);
        convertView.setTag(holder);

        mHashMap.put(position,convertView);
        Bean b = new Bean();
        b.pb = holder.cdp;
        b.current = position * 3;

        mList.add(b);

        holder.cdp.setProgress(mList.get(position).current+temp);
        return convertView;
    }

    class ViewHolder {
        ProgressBar cdp;
    }

    class  Bean{
        int current;
        ProgressBar pb;
    }

    int temp = 1;
    CountDownTimer countDownTimer = new CountDownTimer(100000000,1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            temp+=1;
            for (int key : mHashMap.keySet()) {
                Log.d("WJQ","ttick: "+mHashMap.size());
                Log.d("WJQ","tticksadf: "+mHashMap.get(key).getId());
//                ((ProgressBar)(mHashMap.get(key).findViewById(R.id.pb))).setProgress(temp);

            }

            for (int i = 0; i < mList.size(); i++) {
                Bean b = mList.get(i);
                b.pb.setProgress(b.current+temp);
            }
        }

        @Override
        public void onFinish() {

        }
    };
}
